home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Musik / Misc / Amster / Source / gui.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-01  |  22.2 KB  |  664 lines

  1. /*
  2. ** GUI Functions
  3. */
  4.  
  5. #include "include/config.h"
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <stdarg.h>
  10. #include <string.h>
  11.  
  12. #include <exec/memory.h>
  13.  
  14. #include <proto/asl.h>
  15. #include <proto/dos.h>
  16. #include <proto/icon.h>
  17. #include <proto/utility.h>
  18.  
  19. #include <libraries/gadtools.h>
  20. #include <libraries/asl.h>
  21.  
  22. #include "include/mui.h"
  23. #include <MUI/Lamp_mcc.h>
  24. #include <MUI/NListview_mcc.h>
  25.  
  26. #include "include/gui.h"
  27. #include "include/protos.h"
  28. #include "include/channellist.h"
  29. #include "include/napster.h"
  30. #include "include/transfer.h"
  31. #include "include/download.h"
  32. #include "include/upload.h"
  33. #include "include/prefs.h"
  34. #include "include/hotlist.h"
  35. #include "include/info.h"
  36. #include "include/msg.h"
  37. #include "include/navigator.h"
  38. #include "include/rexx.h"
  39. #include "include/search.h"
  40. #include "include/resultview.h"
  41. #include "include/share.h"
  42. #include "include/panel.h"
  43. #include "include/chat.h"
  44. #include "include/about.h"
  45. #include "include/thread.h"
  46. #include "include/url.h"
  47. #include "amster_Cat.h"
  48.  
  49. struct Library *MUIMasterBase=0;
  50. struct Library *NListBase=0;
  51. struct Library *LampBase=0;
  52. struct Library *TWFBase=0;
  53. int UseLamps = 0;
  54. int UseTWF = 0;
  55. struct guidata mygui;
  56. struct guidata *gui = &mygui;
  57. int gui_napon=0;
  58. int gui_napcon=0;
  59.  
  60. void gui_free(void);
  61. int gui_setup(void);
  62. MUIF gui_handle(REG(a0) struct Hook *h,REG(a2) Object *app, REG(a1) u_long *id);
  63. void gui_about(void);
  64. void gui_appicon(int t);
  65.  
  66. struct Hook handleHook = {{0,0}, &gui_handle, NULL, NULL};
  67.  
  68.  
  69. void gui_run(unsigned long tcpsig)
  70. {
  71.     ULONG sigs=0;
  72.  
  73.     memset(gui,0,sizeof(struct guidata));
  74.     if (gui_setup()) {
  75.         prf_event(PRFE_STARTUP);
  76.         DoMethod(gui->shwin, SHARE_LOAD);
  77.         while (1) {
  78.             while (DoMethod(gui->app, MUIM_Application_NewInput, &sigs) != MUIV_Application_ReturnID_Quit) {
  79.                 if (sigs) {
  80.                     sigs = Wait(sigs|SIGBREAKF_CTRL_C|tcpsig|th_sigmask);
  81.                     if (sigs&SIGBREAKF_CTRL_C) break;
  82.                     if (sigs&tcpsig) nap_listen();
  83.                     if (sigs&th_sigmask) th_poll();
  84.                 }
  85.             }
  86.             if (!dl_count && !ul_count) break;
  87.             if ((dl_count || ul_count) && MUI_Request(gui->app, gui->win, 0L,
  88.                                        (char *)MSG_REALLYQUIT_TITLE,
  89.                                        (char *)MSG_REALLYQUIT_GAD,
  90.                                        (char *)MSG_REALLYQUIT)) break;
  91.         }
  92.         prf_event(PRFE_EXIT);
  93.         if (prf->autosave && sharechanged) DoMethod(gui->shwin, SHARE_SAVE);
  94.         if (prf->ServerList > 0 && ServerListChanged) DoMethod(gui->WI_Navigator, NAVI_SAVE);
  95.         if (HotlistChanged) DoMethod(gui->WI_Hotlist, HOTLIST_SAVE);
  96.         if (gui_napon || gui_napcon) nap_logout();
  97.     }
  98.     gui_free();
  99. }
  100.  
  101.  
  102. void gui_free(void)
  103. {
  104.     gui_appicon(-1);
  105.     if (gui->app) MUI_DisposeObject(gui->app);
  106.     lamp_dispose();
  107.     if (gui->url_mcc) MUI_DeleteCustomClass(gui->url_mcc);
  108.     if (gui->msg_mcc) MUI_DeleteCustomClass(gui->msg_mcc);
  109.     if (gui->info_mcc) MUI_DeleteCustomClass(gui->info_mcc);
  110.     if (gui->about_mcc) MUI_DeleteCustomClass(gui->about_mcc);
  111.     if (gui->prf_mcc) MUI_DeleteCustomClass(gui->prf_mcc);
  112.     if (gui->dl_mcc) MUI_DeleteCustomClass(gui->dl_mcc);
  113.     if (gui->ul_mcc) MUI_DeleteCustomClass(gui->ul_mcc);
  114.     if (gui->share_mcc) MUI_DeleteCustomClass(gui->share_mcc);
  115.     if (gui->search_mcc) MUI_DeleteCustomClass(gui->search_mcc);
  116.     if (gui->resultview_mcc) MUI_DeleteCustomClass(gui->resultview_mcc);
  117.     if (gui->panel_mcc) MUI_DeleteCustomClass(gui->panel_mcc);
  118.     if (gui->chat_mcc) MUI_DeleteCustomClass(gui->chat_mcc);
  119.     if (gui->navi_mcc) MUI_DeleteCustomClass(gui->navi_mcc);
  120.     if (gui->hotlist_mcc) MUI_DeleteCustomClass(gui->hotlist_mcc);
  121.     if (gui->channellist_mcc) MUI_DeleteCustomClass(gui->channellist_mcc);
  122.     if (MUIMasterBase) CloseLibrary(MUIMasterBase);
  123. }
  124.  
  125.  
  126. int gui_setup(void)
  127. {
  128.     long winopen;
  129.     u_long *MI_Navigator, *MI_Connect, *MI_ConnectTo, *MI_Reconnect, *MI_Disconnect;
  130.     u_long *aboutmenu, *muimenu, *helpmenu, *hidemenu, *quitmenu;
  131.     u_long *openmenu, *savemenu, *saveasmenu;
  132.     u_long *debugmenu, *dlmenu, *ulmenu, *sharemenu, *usermenu, *chatmenu, *MI_Hotlist;
  133.     u_long *muiprfmenu, *prfmenu, *MI_LastSaved, *saveprfmenu;
  134.     u_long *rxexemenu;
  135.  
  136.     localize_array(nap_linktype);
  137.  
  138.     MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN);
  139.     if (!MUIMasterBase) {
  140.         printf(MSG_NO_LIBRARY, MUIMASTER_NAME, MUIMASTER_VMIN);
  141.         return(0);
  142.     }
  143.  
  144.     NListBase = OpenLibrary("MUI/NList.mcc", 19);
  145.     if (!NListBase) {
  146.         printf(MSG_NO_LIBRARY, "NList.mcc", 19);
  147.         return(0);
  148.     }
  149.     if (NListBase->lib_Version == 19 && NListBase->lib_Revision < 97) {
  150.         printf(MSG_NO_LIBRARY, "NList.mcc", 19);
  151.         CloseLibrary(NListBase);
  152.         return(0);
  153.     }
  154.     CloseLibrary(NListBase);
  155.  
  156.     LampBase = OpenLibrary("MUI/Lamp.mcc", 11);
  157.     if (LampBase) {
  158.         if (!(LampBase->lib_Version == 11 && LampBase->lib_Revision == 0))
  159.             UseLamps = 1;
  160.         CloseLibrary(LampBase);
  161.     }
  162.     TWFBase = OpenLibrary("MUI/TWFmultiLED.mcc", 12);
  163.     if (TWFBase) {
  164.         if (!(TWFBase->lib_Version == 12 && TWFBase->lib_Revision < 6))
  165.             UseTWF = 1;
  166.         CloseLibrary(TWFBase);
  167.     }
  168.  
  169.     if (!prf_load("ENV:"AMSTER_PREFS)) prf_load("ENVARC:"AMSTER_PREFS);
  170.  
  171.     lamp_create();
  172.  
  173.     gui->url_mcc = MUI_CreateCustomClass(NULL,MUIC_Text,NULL,sizeof(struct urldata),url_dispatch);
  174.     if (!gui->url_mcc) return(0);
  175.  
  176.     gui->panel_mcc = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct paneldata),panel_dispatch);
  177.     if (!gui->panel_mcc) return(0);
  178.  
  179.     gui->search_mcc = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct searchdata),search_dispatch);
  180.     if (!gui->search_mcc) return(0);
  181.  
  182.     gui->resultview_mcc = MUI_CreateCustomClass(NULL,MUIC_Group,NULL,sizeof(struct resultdata),resultview_dispatch);
  183.     if (!gui->resultview_mcc) return(0);
  184.  
  185.     gui->dl_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct TransferData),dl_dispatch);
  186.     if (!gui->dl_mcc) return(0);
  187.  
  188.     gui->ul_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct TransferData),ul_dispatch);
  189.     if (!gui->ul_mcc) return(0);
  190.  
  191.     gui->share_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct shdata),share_dispatch);
  192.     if (!gui->share_mcc) return(0);
  193.  
  194.     gui->prf_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct prfdata),prf_dispatch);
  195.     if (!gui->prf_mcc) return(0);
  196.  
  197.     gui->info_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct infodata),info_dispatch);
  198.     if (!gui->info_mcc) return(0);
  199.  
  200.     gui->about_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct aboutdata),about_dispatch);
  201.     if (!gui->about_mcc) return(0);
  202.  
  203.     gui->msg_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct msgdata),msg_dispatch);
  204.     if (!gui->msg_mcc) return(0);
  205.  
  206.     gui->chat_mcc = MUI_CreateCustomClass(NULL,MUIC_Window,NULL,sizeof(struct chatdata),chat_dispatch);
  207.     if (!gui->chat_mcc) return(0);
  208.  
  209.     gui->navi_mcc = MUI_CreateCustomClass(NULL, MUIC_Window, NULL, sizeof(struct NavigatorData), NavigatorDispatch);
  210.     if (!gui->navi_mcc) return(0);
  211.  
  212.     gui->hotlist_mcc = MUI_CreateCustomClass(NULL, MUIC_Window, NULL, sizeof(struct HotlistData), HotlistDispatch);
  213.     if (!gui->hotlist_mcc) return(0);
  214.  
  215.     gui->channellist_mcc = MUI_CreateCustomClass(NULL, MUIC_Window, NULL, sizeof(struct ChannelListData), ChannelListDispatch);
  216.     if (!gui->channellist_mcc) return(0);
  217.  
  218.     gui->app = ApplicationObject,
  219.         MUIA_Application_Title,       "Amster",
  220.         MUIA_Application_Version,     "$VER: Amster "AMSTER_VERSION" ("AMSTER_DATE")",
  221.         MUIA_Application_Author,      "Jacob Laursen",
  222.         MUIA_Application_Description, MSG_CX_DESCRIPTION,
  223.         MUIA_Application_Base,        "AMSTER",
  224.         MUIA_Application_Commands,    &rexx_cmds,
  225.         MUIA_Application_HelpFile,    AMSTER_HELP,
  226.         MUIA_Application_Menustrip,   MenustripObject,
  227.             Child, MenuObject,
  228.                 MUIA_Menu_Title, MSG_AMSTER_MENU,
  229.                 Child, MI_Navigator = makemenu(MSG_AMSTER_NAVIGATOR),
  230.                 Child, makemenu(NULL),
  231.                 Child, MI_Connect = makemenu(MSG_AMSTER_CONNECT),
  232.                 Child, MI_ConnectTo = makemenu(MSG_AMSTER_CONNECTTO),
  233.                 Child, MI_Reconnect = makemenu(MSG_AMSTER_RECONNECT),
  234.                 Child, MI_Disconnect = makemenu(MSG_AMSTER_DISCONNECT),
  235.                 Child, makemenu(NULL),
  236.                 Child, aboutmenu = makemenu(MSG_AMSTER_ABOUT),
  237.                 Child, muimenu = makemenu(MSG_AMSTER_ABOUTMUI),
  238.                 Child, helpmenu = makemenu(MSG_AMSTER_HELP),
  239.                 Child, makemenu(NULL),
  240.                 Child, hidemenu = makemenu(MSG_AMSTER_HIDE),
  241.                 Child, quitmenu = makemenu(MSG_AMSTER_QUIT),
  242.             End,
  243.             Child, MenuObject,
  244.                 MUIA_Menu_Title, MSG_PROJECT_MENU,
  245.                 Child, openmenu = makemenu(MSG_PROJECT_OPEN),
  246.                 Child, savemenu = makemenu(MSG_PROJECT_SAVE),
  247.                 Child, saveasmenu = makemenu(MSG_PROJECT_SAVEAS),
  248.             End,
  249.             Child, MenuObject,
  250.                 MUIA_Menu_Title, MSG_WINDOWS_MENU,
  251.                 Child, debugmenu = makemenu(MSG_WINDOWS_DEBUG),
  252.                 Child, sharemenu = makemenu(MSG_WINDOWS_SHARE),
  253.                 Child, dlmenu = makemenu(MSG_WINDOWS_DOWNLOAD),
  254.                 Child, ulmenu = makemenu(MSG_WINDOWS_UPLOAD),
  255.                 Child, usermenu = makemenu(MSG_WINDOWS_USER),
  256.                 Child, chatmenu = makemenu(MSG_WINDOWS_CHAT),
  257.                 Child, MI_Hotlist = makemenu(MSG_WINDOWS_HOTLIST),
  258.             End,
  259.             Child, MenuObject,
  260.                 MUIA_Menu_Title, MSG_SETTINGS_MENU,
  261.                 Child, gui->iconpanelmenu = maketmenu(MSG_SETTINGS_ICONPANEL),
  262.                 Child, makemenu(NULL),
  263.                 Child, muiprfmenu = makemenu(MSG_SETTINGS_MUI),
  264.                 Child, prfmenu = makemenu(MSG_SETTINGS_CONFIG),
  265.                 Child, makemenu(NULL),
  266.                 Child, MI_LastSaved = makemenu(MSG_SETTINGS_LASTSAVED),
  267.                 Child, saveprfmenu = makemenu(MSG_SETTINGS_SAVE),
  268.             End,
  269.             Child, MenuObject,
  270.                 MUIA_Menu_Title, MSG_AREXX_MENU,
  271.                 Child, rxexemenu = makemenu(MSG_AREXX_EXECUTE),
  272.             End,
  273.         End,
  274.  
  275.         SubWindow, gui->win = WindowObject,
  276.         MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  277.         MUIA_Window_Title, "Amster v"AMSTER_VERSION,
  278.         WindowContents, HGroup,
  279.             Child, VGroup,
  280.                 Child, gui->searchpanel = NewObject(gui->search_mcc->mcc_Class,NULL,TAG_DONE),
  281.                 Child, RectangleObject,
  282.                     MUIA_FixHeight, 8,
  283.                     MUIA_Rectangle_HBar, TRUE,
  284.                 End,
  285.                 Child, gui->statgrp = HGroup,
  286.                     Child, gui->stat = TextObject,
  287.                         TextFrame,
  288.                         MUIA_Background, MUII_TextBack,
  289.                         MUIA_Text_PreParse, "\33c",
  290.                     End,
  291.                 End,
  292.                 Child, HGroup,
  293.                     Child, gui->inbut  = SimpleButton(MSG_CONNECT_GAD),
  294.                     Child, gui->outbut = SimpleButton(MSG_DISCONNECT_GAD),
  295.                     Child, gui->rebut  = SimpleButton(MSG_RECONNECT_GAD),
  296.                 End,
  297.             End,
  298.             Child, gui->rect = HGroup,
  299.                 Child, RectangleObject,
  300.                     MUIA_FixWidth, 4,
  301.                     MUIA_Rectangle_VBar, TRUE,
  302.                 End,
  303.                 Child, gui->iconpanel = NewObject(gui->panel_mcc->mcc_Class,NULL,TAG_DONE),
  304.             End,
  305.         End,
  306.         End,
  307.  
  308.         SubWindow, gui->WI_ConnectTo = WindowObject,
  309.         MUIA_HelpNode, "connectto",
  310.         MUIA_Window_Title, MSG_CONNECTTO_TITLE,
  311.         MUIA_Window_ID, MAKE_ID('C','O','N','N'),
  312.         WindowContents, VGroup,
  313.             Child, HGroup,
  314.                 Child, ColGroup(2),
  315.                     Child, Label2(MSG_CONNECTTO_SERVER),
  316.                     Child, gui->ST_ConnectServer = StringObject,
  317.                         StringFrame,
  318.                         MUIA_CycleChain, 1,
  319.                     End,
  320.                     Child, Label2(MSG_CONNECTTO_USERNAME),
  321.                     Child, gui->ST_ConnectUser = StringObject,
  322.                         StringFrame,
  323.                         MUIA_CycleChain, 1,
  324.                     End,
  325.                     Child, Label2(MSG_CONNECTTO_PASSWORD),
  326.                     Child, gui->ST_ConnectPw = StringObject,
  327.                         StringFrame,
  328.                         MUIA_String_Secret, TRUE,
  329.                         MUIA_CycleChain, 1,
  330.                     End,
  331.                 End,
  332.             End,
  333.             Child, maketoggle(MSG_CONNECTTO_REG, &gui->TG_ConnectReg),
  334.             Child, gui->BT_ConnectServer = SimpleButton(MSG_CONNECTTO_CONNECT_GAD),
  335.         End,
  336.         End,
  337.  
  338.         SubWindow, gui->awin = NewObject(gui->about_mcc->mcc_Class, NULL, TAG_DONE),
  339.         SubWindow, gui->swin = NewObject(gui->prf_mcc->mcc_Class, NULL, TAG_DONE),
  340.         SubWindow, gui->iwin = NewObject(gui->info_mcc->mcc_Class, NULL, TAG_DONE),
  341.         SubWindow, gui->dwin = NewObject(gui->dl_mcc->mcc_Class, NULL, TAG_DONE),
  342.         SubWindow, gui->uwin = NewObject(gui->ul_mcc->mcc_Class, NULL, TAG_DONE),
  343.         SubWindow, gui->shwin = NewObject(gui->share_mcc->mcc_Class, NULL, TAG_DONE),
  344.         SubWindow, gui->mwin = NewObject(gui->msg_mcc->mcc_Class, NULL, TAG_DONE),
  345.         SubWindow, gui->WI_Navigator = NewObject(gui->navi_mcc->mcc_Class, NULL, TAG_DONE),
  346.         SubWindow, gui->WI_Hotlist = NewObject(gui->hotlist_mcc->mcc_Class, NULL, TAG_DONE),
  347.         SubWindow, gui->WI_ChannelList = NewObject(gui->channellist_mcc->mcc_Class, NULL, TAG_DONE),
  348.  
  349.     End;
  350.  
  351.     if (!gui->app) {
  352.         printf(MSG_APP_ERROR);
  353.         return(0);
  354.     }
  355.  
  356.     DoMethod(gui->inbut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, CONNECT);
  357.     DoMethod(gui->outbut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, DISCONNECT);
  358.     DoMethod(gui->rebut,MUIM_Notify,MUIA_Pressed,FALSE,gui->app,3,MUIM_CallHook,&handleHook, RECONNECT);
  359.  
  360.     DoMethod(gui->iconpanelmenu,MUIM_Notify,MUIA_Menuitem_Checked,MUIV_EveryTime,gui->app,3,MUIM_CallHook,&handleHook, UPDATEPANEL);
  361.  
  362.     DoMethod(MI_Navigator, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->WI_Navigator, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  363.     DoMethod(MI_Connect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, CONNECT);
  364.     DoMethod(MI_ConnectTo, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->WI_ConnectTo, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  365.     DoMethod(MI_Reconnect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, RECONNECT);
  366.     DoMethod(MI_Disconnect, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->app, 3, MUIM_CallHook, &handleHook, DISCONNECT);
  367.     DoMethod(gui->WI_ConnectTo, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, gui->WI_ConnectTo, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  368.  
  369.     /* Connect to... */
  370.  
  371.     DoMethod(gui->BT_ConnectServer, MUIM_Notify, MUIA_Pressed, FALSE, gui->app, 3, MUIM_CallHook, &handleHook, CONNECTSERVER);
  372.  
  373.     /* Pulldown menu */
  374.  
  375.     DoMethod(aboutmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->awin,3,MUIM_Set,MUIA_Window_Open,TRUE);
  376.     DoMethod(muimenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_AboutMUI,gui->win);
  377.     DoMethod(helpmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,5,MUIM_Application_ShowHelp,gui->win,AMSTER_HELP,0,0);
  378.     DoMethod(hidemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,3,MUIM_Set,MUIA_Application_Iconified,TRUE);
  379.     DoMethod(quitmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  380.  
  381.     DoMethod(openmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->shwin,1,SHARE_LOADAS);
  382.     DoMethod(savemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->shwin,1,SHARE_SAVE);
  383.     DoMethod(saveasmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->shwin,1,SHARE_SAVEAS);
  384.  
  385.     DoMethod(debugmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENDEBUG);
  386.     DoMethod(dlmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENDL);
  387.     DoMethod(ulmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->uwin,1,UPLOAD_OPEN);
  388.     DoMethod(sharemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENSHARE);
  389.     DoMethod(usermenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENMSG);
  390.     DoMethod(chatmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_NEWCHAT);
  391.     DoMethod(MI_Hotlist, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->WI_Hotlist, 3, MUIM_Set, MUIA_Window_Open, TRUE);
  392.  
  393.     DoMethod(muiprfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,2,MUIM_Application_OpenConfigWindow,0);
  394.     DoMethod(prfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->iconpanel,1,PANEL_OPENPRF);
  395.     DoMethod(MI_LastSaved, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, gui->swin, 1, PRF_LASTSAVED);
  396.     DoMethod(saveprfmenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->swin,1,PRF_SAVEALL);
  397.  
  398.     DoMethod(rxexemenu,MUIM_Notify,MUIA_Menuitem_Trigger,MUIV_EveryTime,gui->app,3,MUIM_CallHook,&handleHook, EXECUTEAREXX);
  399.  
  400.     DoMethod(gui->win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,gui->app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  401.     DoMethod(gui->app, MUIM_Notify, MUIA_Application_Iconified, FALSE, gui->app,3, MUIM_CallHook, &handleHook, DEICONIFIED);
  402.  
  403.     if (UseLamps) DoMethod(gui->statgrp, OM_ADDMEMBER, gui->lamp = LampObject, MUIA_Lamp_Type, MUIV_Lamp_Type_Huge, MUIA_Lamp_Color, MUIV_Lamp_Color_Off, End);
  404.  
  405.     DoMethod(gui->searchpanel, SEARCH_SET);
  406.  
  407.     set(gui->ST_ConnectUser, MUIA_String_Contents, prf->user);
  408.     set(gui->ST_ConnectPw,   MUIA_String_Contents, prf->pass);
  409.     set(gui->TG_ConnectReg,  MUIA_Selected,        TRUE);
  410.  
  411.     if (prf->noiconpanel) {
  412.         set(gui->iconpanelmenu, MUIA_Menuitem_Checked, FALSE);
  413.         set(gui->rect, MUIA_ShowMe, FALSE);
  414.     }
  415.     else {
  416.         set(gui->iconpanelmenu, MUIA_Menuitem_Checked, TRUE);
  417.     }
  418.  
  419.     gui_appicon(0);
  420.     gui_state(-2);
  421.  
  422.     if (!UseLamps) gui_debug((char *)MSG_INFO_NOLAMPS);
  423.  
  424.     /* Set screen title for all windows */
  425.     DoMethod(gui->app, MUIM_MultiSet, MUIA_Window_ScreenTitle,
  426.         "Amster "AMSTER_VERSION" ("AMSTER_DATE") © 1999-2000 Gürer Özen & Jacob Laursen",
  427.         gui->win, gui->awin, gui->swin, gui->shwin, gui->mwin, gui->iwin,
  428.         gui->dwin, gui->uwin, gui->WI_ConnectTo, gui->WI_Navigator,
  429.         gui->WI_Hotlist, gui->WI_ChannelList, NULL);
  430.  
  431.     set(gui->win, MUIA_Window_Open, TRUE);
  432.     get(gui->win, MUIA_Window_Open, &winopen);
  433.     if (!winopen) {
  434.         printf(MSG_ERR_NOWINDOW);
  435.         return(0);
  436.     }
  437.  
  438.     if (!prf->user) DoMethod(gui->iconpanel, PANEL_OPENPRF);
  439.     /* If no account is configured, open configuration window */
  440.  
  441.     if (prf->user && prf->autocon) {
  442.         nap_login();
  443.         return(1);
  444.     }
  445.  
  446.     set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_NOTCONNECTED);
  447.     return(1);
  448. }
  449.  
  450.  
  451. MUIF gui_handle(REG(a0) struct Hook *h, REG(a2) Object *app, REG(a1) u_long *id)
  452. {
  453.     u_long tmp;
  454.     char *buf;
  455.  
  456.     switch(*id) {
  457.         case CONNECT:
  458.             if (!gui_napon) nap_login();
  459.             break;
  460.         case DISCONNECT:
  461.             nap_logout();
  462.             set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_NOTCONNECTED);
  463.             break;
  464.         case RECONNECT:
  465.             if (gui_napon) nap_logout();
  466.             nap_login();
  467.             break;
  468.         case CONNECTSERVER:
  469.             if (gui_napon) nap_logout();
  470.             get(gui->ST_ConnectServer, MUIA_String_Contents, &buf);
  471.             get(gui->ST_ConnectUser,   MUIA_String_Contents, &gui->ConnectUser);
  472.             get(gui->ST_ConnectPw,     MUIA_String_Contents, &gui->ConnectPw);
  473.             get(gui->TG_ConnectReg,    MUIA_Selected,        &tmp);
  474.             set(gui->WI_ConnectTo, MUIA_Window_Open, FALSE);
  475.             if (tmp) prf->regflag = 2;
  476.             else prf->regflag = 0;
  477.             nap_login_fromlist(buf);
  478.             break;
  479.         case EXECUTEAREXX:
  480.             {
  481.             BPTR lock;
  482.             struct FileRequester *freq;
  483.             u_long win;
  484.             char DefaultDir[256] = "";
  485.  
  486.             lock = Lock("PROGDIR:Rexx/", ACCESS_READ);
  487.             if (lock) {
  488.                 NameFromLock(lock, DefaultDir, 255);
  489.                 UnLock(lock);
  490.             }
  491.  
  492.             get(gui->win, MUIA_Window_Window, &win);
  493.             freq = AllocAslRequestTags(ASL_FileRequest, TAG_DONE);
  494.             if (!freq) break;
  495.             tmp = AslRequestTags(freq,
  496.                 ASLFR_Window, win,
  497.                 ASLFR_TitleText, MSG_SELECTRX_TITLE,
  498.                 ASLFR_InitialDrawer, DefaultDir,
  499.                 ASLFR_DoSaveMode, FALSE,
  500.                 TAG_DONE);
  501.             if (tmp) {
  502.                 static char buf[512];
  503.                 strcpy(buf, freq->fr_Drawer);
  504.                 AddPart(buf, freq->fr_File,511);
  505.                 rexx_execute(buf, NULL);
  506.             }
  507.             FreeAslRequest(freq);
  508.             break;
  509.             }
  510.         case UPDATEPANEL:
  511.             GetAttr(MUIA_Menuitem_Checked, gui->iconpanelmenu, &tmp);
  512.             if (tmp==TRUE)
  513.                 set(gui->rect, MUIA_ShowMe, TRUE);
  514.             else
  515.                 set(gui->rect, MUIA_ShowMe, FALSE);
  516.             break;
  517.         case DEICONIFIED:
  518.             /* Work-around for a bug in Lamp.mcc */
  519.             if (!gui_napon && !gui_napcon) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Off);
  520.             else if (gui_napon && !gui_napcon) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Ok);
  521.             else set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Connecting);
  522.             break;
  523.     }
  524.     return(0);
  525. }
  526.  
  527.  
  528. void gui_state(int s)
  529. {
  530.     u_long tmp;
  531.     static char title[128];
  532.  
  533.     switch (s) {
  534.         case -1:
  535.             prf_event(PRFE_DISCONNECT);
  536.             DoMethod(gui->WI_Hotlist, HOTLIST_SIGNOFF_ALL);
  537.         case -2:    /* Offline */
  538.             gui_napon = 0;
  539.             gui_napcon = 0;
  540.             set(gui->inbut, MUIA_Disabled, FALSE);
  541.             set(gui->outbut, MUIA_Disabled, TRUE);
  542.             set(gui->rebut, MUIA_Disabled, TRUE);
  543.  
  544.             sprintf(title, "Amster v%s · %s", AMSTER_VERSION, MSG_MAIN_TITLE_NOTCONNECTED);
  545.             set(gui->win, MUIA_Window_Title, title);
  546.  
  547.             /* Work-around for a bug in Lamp.mcc */
  548.             get(gui->app, MUIA_Application_Iconified, &tmp);
  549.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Off);
  550.  
  551.             DoMethod(gui->searchpanel, SEARCH_CLEAR, CLEAR_ALL);
  552.             DoMethod(gui->WI_Hotlist, HOTLIST_CLEAR, CLEAR_ALL);
  553.             gui_appicon(2);
  554.             break;
  555.         case 0:    /* Connecting */
  556.             gui_napcon = 1;
  557.             set(gui->inbut, MUIA_Disabled, TRUE);
  558.             set(gui->outbut, MUIA_Disabled, FALSE);
  559.  
  560.             sprintf(title, "Amster v%s · %s", AMSTER_VERSION, MSG_MAIN_TITLE_NOTCONNECTED);
  561.             set(gui->win, MUIA_Window_Title, title);
  562.  
  563.             /* Work-around for a bug in Lamp.mcc */
  564.             get(gui->app, MUIA_Application_Iconified, &tmp);
  565.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Connecting);
  566.  
  567.             set(gui->stat, MUIA_Text_Contents, MSG_STATUS2_CONNECTING);
  568.             break;
  569.         case 1:    /* Logging in */
  570.             prf_event(PRFE_CONNECT);
  571.             gui_napon = 1;
  572.             gui_napcon = 0;
  573.             set(gui->inbut, MUIA_Disabled, TRUE);
  574.             set(gui->outbut, MUIA_Disabled, FALSE);
  575.             set(gui->rebut, MUIA_Disabled, FALSE);
  576.  
  577.             sprintf(title, "Amster v%s · %s", AMSTER_VERSION, nap_server);
  578.             set(gui->win, MUIA_Window_Title, title);
  579.  
  580.             /* Work-around for a bug in Lamp.mcc */
  581.             get(gui->app, MUIA_Application_Iconified, &tmp);
  582.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_SendingData);
  583.  
  584.             break;
  585.         case 2:    /* Online */
  586.             gui_napon = 1;
  587.             gui_napcon = 0;
  588.             set(gui->inbut, MUIA_Disabled, TRUE);
  589.             set(gui->outbut, MUIA_Disabled, FALSE);
  590.             set(gui->rebut, MUIA_Disabled, FALSE);
  591.  
  592.             sprintf(title, "Amster v%s · %s", AMSTER_VERSION, nap_server);
  593.             set(gui->win, MUIA_Window_Title, title);
  594.  
  595.             /* Work-around for a bug in Lamp.mcc */
  596.             get(gui->app, MUIA_Application_Iconified, &tmp);
  597.             if (!tmp) set(gui->lamp, MUIA_Lamp_Color, MUIV_Lamp_Color_Ok);
  598.  
  599.             gui_appicon(1);
  600.             break;
  601.     }
  602. }
  603.  
  604.  
  605. void gui_srvstat(int a, int b, int c)
  606. {
  607.     gui_stat((char*)MSG_STATUS2_SONGSONLINE, b, a, c);
  608. }
  609.  
  610.  
  611. void gui_found(song s, int type)
  612. {
  613.     if (type == 0) DoMethod(gui->searchpanel, SEARCH_FOUND, s);
  614.     else if (type == 1) DoMethod(gui->WI_Hotlist, HOTLIST_FOUND, s);
  615. }
  616.  
  617.  
  618. void localize_array(char *array[])
  619. {
  620.     char **x;
  621.  
  622.     for (x=array;*x;x++)
  623.         *x = (char *)((struct FC_String *)(*x))->msg;
  624. }
  625.  
  626.  
  627. void gui_stat(char *msg, ...)
  628. {
  629.     static char buf[256];
  630.     va_list ap;
  631.  
  632.     va_start(ap,msg);
  633.     vsprintf(buf,msg,ap);
  634.     va_end(ap);
  635.     set(gui->stat, MUIA_Text_Contents, buf);
  636. }
  637.  
  638.  
  639. void gui_appicon(int t)
  640. {
  641.     static struct DiskObject *on, *off;
  642.  
  643.     switch(t) {
  644.         case 0:
  645.             on = GetDiskObject("PROGDIR:Icons/Amster_online");
  646.             off = GetDiskObject("PROGDIR:Icons/Amster_offline");
  647.             break;
  648.  
  649.         case -1:
  650.             if (on) FreeDiskObject(on);
  651.             if (off) FreeDiskObject(off);
  652.             break;
  653.  
  654.         case 1:
  655.             if (on) set(gui->app, MUIA_Application_DiskObject, on);
  656.             break;
  657.  
  658.         case 2:
  659.             if (off) set(gui->app, MUIA_Application_DiskObject, off);
  660.             break;
  661.  
  662.     }
  663. }
  664.